package com.xjoyt.pay.master.controllers;

import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xjoyt.pay.commons.PayTypeUtils;
import com.xjoyt.pay.controllers.AbstractController;
import com.xjoyt.pay.dto.ExecuteResult;
import com.xjoyt.pay.dto.PageParam;
import com.xjoyt.pay.dto.PageResult;
import com.xjoyt.pay.gateway.params.AlipayOrderParam;
import com.xjoyt.pay.gateway.params.AlipayWapPayParam;
import com.xjoyt.pay.gateway.params.BankPayParam;
import com.xjoyt.pay.gateway.params.CallbackParam;
import com.xjoyt.pay.gateway.params.ScannedCodeParam;
import com.xjoyt.pay.gateway.params.WechatOrderParam;
import com.xjoyt.pay.gateway.params.WechatWapPayParam;
import com.xjoyt.pay.master.dto.CallbackResult;
import com.xjoyt.pay.master.dto.OrderUrlResult;
import com.xjoyt.pay.master.interfaces.OrderContract;
import com.xjoyt.pay.master.params.MerchantOrderGroupParam;
import com.xjoyt.pay.master.params.OrderPageParam;
import com.xjoyt.pay.master.po.Order;
import com.xjoyt.pay.master.services.OrderService;
import com.xjoyt.pay.master.vo.MerchantOrderGroup;
import com.xjoyt.pay.master.vo.OrderMap;
import com.xjoyt.pay.master.vo.OrderParam;
import com.xjoyt.pay.vo.PayType;

@RestController
@RequestMapping("order")
public class OrderController extends AbstractController implements OrderContract {

	@Autowired
	private OrderService service;

	@Override
	public Map<PayType, String> getAllPayType() {
		return PayTypeUtils.getAllPayType();
	}

	@Override
	public Order get(@PathVariable("id") String id) {
		return service.get(id);
	}

	@Override
	public PageResult<Order> loadPage(@RequestBody PageParam<OrderPageParam> param) {
		return service.loadPage(param);
	}

	@Override
	public PageResult<OrderMap> loadPageMap(@RequestBody PageParam<OrderPageParam> param) {
		return service.loadPageMap(param);
	}

	@Override
	public ExecuteResult<CallbackResult> callback(@Valid @RequestBody CallbackParam param) throws Exception {
		return service.callback(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> wechatScan(@RequestBody WechatOrderParam param) {
		return service.wechatScan(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> alipayScan(@RequestBody AlipayOrderParam param) {
		return service.alipayScan(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> bankPay(@RequestBody BankPayParam param) {
		return service.bankPay(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> alipayWapPay(@RequestBody AlipayWapPayParam param) {
		return service.alipayWapPay(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> wechatWapPay(@RequestBody WechatWapPayParam param) {
		return service.wechatWapPay(param);
	}

	@Override
	public ExecuteResult<OrderUrlResult> scannedCodePay(@RequestBody ScannedCodeParam param) {
		return service.scannedCodePay(param);
	}

	@Override
	public Order getByNo(@PathVariable("no") String no) {
		return service.getByNo(no);
	}

	@Override
	public Order getByCustomerNo(@PathVariable("customerNo") String customerNo) {
		return service.getByCustomerNo(customerNo);
	}

	@Override
	public ExecuteResult<Order> checkout(@RequestBody OrderParam param) {
		return service.checkout(param);
	}

	@Override
	public PageResult<MerchantOrderGroup> loadPageGroup(@RequestBody PageParam<MerchantOrderGroupParam> params) {
		return service.loadPageGroup(params);
	}

	@Override
	public List<Order> findAll(@RequestBody OrderPageParam param) {
		return service.findAll(param);
	}
}
